package com.zr.system.service.impl;

import java.util.List;
import com.zr.common.utils.DateUtils;
import com.zr.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zr.system.mapper.SysAnnounceMapper;
import com.zr.system.domain.SysAnnounce;
import com.zr.system.service.ISysAnnounceService;

/**
 * 移动端通告Service业务层处理
 * 
 * @author why
 * @date 2022-10-26
 */
@Service
public class SysAnnounceServiceImpl implements ISysAnnounceService 
{
    @Autowired
    private SysAnnounceMapper sysAnnounceMapper;

    /**
     * 查询移动端通告
     * 
     * @param announceId 移动端通告主键
     * @return 移动端通告
     */
    @Override
    public SysAnnounce selectSysAnnounceByAnnounceId(Long announceId)
    {
        return sysAnnounceMapper.selectSysAnnounceByAnnounceId(announceId);
    }

    /**
     * 查询移动端通告列表
     * 
     * @param sysAnnounce 移动端通告
     * @return 移动端通告
     */
    @Override
    public List<SysAnnounce> selectSysAnnounceList(SysAnnounce sysAnnounce)
    {
        return sysAnnounceMapper.selectSysAnnounceList(sysAnnounce);
    }

    /**
     * 新增移动端通告
     * 
     * @param sysAnnounce 移动端通告
     * @return 结果
     */
    @Override
    public int insertSysAnnounce(SysAnnounce sysAnnounce)
    {
        sysAnnounce.setCreateTime(DateUtils.getNowDate());
        sysAnnounce.setCreateBy(SecurityUtils.getUsername());
        return sysAnnounceMapper.insertSysAnnounce(sysAnnounce);
    }

    /**
     * 修改移动端通告
     * 
     * @param sysAnnounce 移动端通告
     * @return 结果
     */
    @Override
    public int updateSysAnnounce(SysAnnounce sysAnnounce)
    {
        sysAnnounce.setUpdateTime(DateUtils.getNowDate());
        sysAnnounce.setUpdateBy(SecurityUtils.getUsername());
        return sysAnnounceMapper.updateSysAnnounce(sysAnnounce);
    }

    /**
     * 批量删除移动端通告
     * 
     * @param announceIds 需要删除的移动端通告主键
     * @return 结果
     */
    @Override
    public int deleteSysAnnounceByAnnounceIds(Long[] announceIds)
    {
        return sysAnnounceMapper.deleteSysAnnounceByAnnounceIds(announceIds);
    }

    /**
     * 删除移动端通告信息
     * 
     * @param announceId 移动端通告主键
     * @return 结果
     */
    @Override
    public int deleteSysAnnounceByAnnounceId(Long announceId)
    {
        return sysAnnounceMapper.deleteSysAnnounceByAnnounceId(announceId);
    }

    /**
     * 根据角色获取最新通告
     * @param roleId
     * @return
     */
    @Override
    public SysAnnounce selectLatestAnnounce(Long roleId) {
        return sysAnnounceMapper.selectLatestAnnounceByRoleId(roleId);
    }
}
